<?php
Yii::import('zii.widgets.jui.CJuiWidget');
class Panel extends CJuiWidget {
	
	public $options = array();
	
	public $panel = array();
	
	public function run()
	{		
		if($this->htmlOptions['id'] == '')
			$this->htmlOptions['id'] = $this->getId();
		$id = $this->htmlOptions['id'];

		$ulHtml = '';
		if(count($this->panel) > 0) {
			foreach($this->panel as $panel_id=>$content) {
				$panelHtml = '';
				if(is_array($content)) {
					$panelHtml = $content;
					$content = '';
				}
				$panelHtml['id'] = $panel_id;
				$liHtml .= CHtml::tag('li',$panelHtml,$content);	
			}
			$ulHtml = CHtml::tag('ul',array(),$liHtml);
		}
		echo CHtml::tag('div',$this->htmlOptions,$ulHtml);
		$js =<<<EOD
$('#$id').winerdyPanel();
EOD;
		$baseUrl = Yii::getPathOfAlias('application.widgets.RiotingNerds.assets.panel');
        $publishurl = Yii::app()->getAssetManager()->publish($baseUrl);
		$cs = Yii::app()->getClientScript();
		$cs->registerScriptFile($publishurl.'/panel.js');
		$cs->registerCssFile($publishurl.'/panel.css');
		$cs->registerScript(__CLASS__.'#'.$id, $js);
	}
}
?>